package com.sinodata.bsm.cicp.collector.storage;

import java.util.ArrayList;
import java.util.List;

import com.sinodata.bsm.cicp.collector.Collector;
import com.sinodata.bsm.cicp.exception.CollectorException;
import com.sinodata.bsm.cicp.service.ReceiveTrapService;
import com.sinodata.bsm.common.vo.ResPropertyValue;
import com.sinodata.bsm.common.vo.Trap;

public class TrapCollector extends Collector {

    @Override
    public String[] getPropMeta() {
        return new String[] { "source", "timestamp", "securityLevel", "securityModel", "commutity", "PDUMessage" };
    }

    @Override
    public String[] getParamMeta() {
        return null;
    }

    @Override
    public List<ResPropertyValue> collect(String ip) throws CollectorException {
        String[] propMetas = getPropMeta();
        List<ResPropertyValue> values = null;
        List<Trap> traps = ReceiveTrapService.getInstance().getTrapsByIp(ip);
        if (traps != null && traps.size() > 0) {
            values = new ArrayList<ResPropertyValue>();
            for (Trap trap : traps) {
                ResPropertyValue propertyValueX = new ResPropertyValue();
                ResPropertyValue.PropValue[] propValues = new ResPropertyValue.PropValue[propMetas.length];
                propValues[0] = ResPropertyValue.createPropValue(trap.getSource(), propMetas[0]);
                propValues[1] = ResPropertyValue.createPropValue(trap.getTimestamp(), propMetas[1]);
                propValues[2] = ResPropertyValue.createPropValue(trap.getSecurityLevel() + "", propMetas[2]);
                propValues[3] = ResPropertyValue.createPropValue(trap.getSecurityModel() + "", propMetas[3]);
                propValues[4] = ResPropertyValue.createPropValue(trap.getCommutity(), propMetas[4]);
                propValues[5] = ResPropertyValue.createPropValue(trap.getPDUMessage(), propMetas[5]);
                propertyValueX.setValues(propValues);
                values.add(propertyValueX);
            }
        }
        return values;
    }
}
